/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servicios;

import entities.EstatusTiempo;
import entities.Tarea;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
/**
 *
 * @author curso
 */
@Stateless
@LocalBean
public class ServicioTarea {
    @PersistenceContext(name="recursividadPU")
    private EntityManager em;
    
    public void guardarTareas(List<Tarea> tareas){
        em.persist(tareas);
    }

    public void guardarTarea(Tarea tarea){
        em.persist(tarea);
    }
    
    public void modificarTarea(Tarea tarea){
        em.merge(tarea);
    }
    
    public void borrar(Long id){
        Tarea tarea =em.find(Tarea.class, id);
        
        if(tarea!=null)
        em.remove(tarea);        
    }
    
    public List<Tarea> verTodas(){
         TypedQuery<Tarea> query = em.createQuery("SELECT t from Tarea t", Tarea.class);
        return query.getResultList();
    }
    
    public List<EstatusTiempo> verStatus(){
       
        List<EstatusTiempo> l = new ArrayList<EstatusTiempo>();
        l.addAll(Arrays.asList(EstatusTiempo.values()));
        
       return l; 
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
}
